import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'chat_logic.dart';
import '../../routes/routes.dart';

// import '../../models/models.dart';
import '../../shared/shared.dart';
import '../../widgets/widgets.dart';

class ChatPage extends GetView<ChatLogic> {
  // final UserMessages userMessage = Get.arguments;

  const ChatPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Stack(children: [
      const Background(imageURL: AssetsURL.chatPage, opacity: 0.59),
      SafeArea(
          child: Scaffold(backgroundColor: Colors.transparent, body: _body()))
    ]);
  }

  Container _body() {
    return Container(
        margin: const EdgeInsets.all(19),
        child: Column(children: [
          _buildRow(),
          Expanded(
            child: Column(
              children: [Obx(() => _eyes()), _history(), _viva()],
            ),
          ),
          Obx(() => _buildBottom())
        ]));
  }

  Center _viva() {
    return Center(
      child: InkWell(
        onTap: () => Get.toNamed(Routes.assistant),
        radius: 0,
        highlightColor: Colors.transparent,
        child: const Text('VIVA',
            style: TextStyle(fontSize: 24, color: Colors.transparent)),
      ),
    );
  }

  Row _history() {
    return Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
      CommonWidget.rowWidth(width: 5),
      IconButton(
          onPressed: () => false,
          icon: IconFont(
            IconNames.history,
            size: 44,
          ))
    ]);
  }

  Row _eyes() {
    return Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
      CommonWidget.rowWidth(width: 5),
      IconButton(
          onPressed: () => controller.open(),
          icon: IconFont(
            controller.eyes.value ? IconNames.eyesOpen : IconNames.eyesClose,
            size: 50,
          ))
    ]);
  }

  Widget _buildBottom() {
    return controller.showInput.value ? _buildInput() : _buildStar();
  }

  Widget _buildInput() {
    return Column(children: [
      _input(),
      CommonWidget.rowHeight(height: 10),
      Obx(() => controller.showOption.value
          ? _function()
          : CommonWidget.rowHeight(height: 1))
    ]);
  }

  Container _function() {
    return Container(
        width: double.infinity,
        height: 90,
        padding: const EdgeInsets.all(15),
        decoration: BoxDecoration(
            color: ColorConstants.themeColor.withOpacity(0.53),
            borderRadius: const BorderRadius.all(Radius.circular(20))),
        child: Row(children: [
          _select('图片', IconNames.picture),
          _select('语音连麦', IconNames.chat)
        ]));
  }

  Widget _select(String text, IconNames icon) {
    return Container(
        margin: const EdgeInsets.symmetric(horizontal: 5),
        child: Column(children: [
          IconFont(icon, size: 43, color: '#707070'),
          Text(text, style: const TextStyle(fontSize: 10))
        ]));
  }

  Widget _input() {
    return Container(
      decoration: BoxDecoration(
          border: Border.all(color: ColorConstants.themeColor, width: 2)),
      child: Row(
        children: [
          _prefixIcon(),
          _inputBox(),
          _suffixIcon(),
        ],
      ),
    );
  }

  Expanded _inputBox() {
    return const Expanded(
      child: TextField(
        decoration: InputDecoration(
            contentPadding: EdgeInsets.all(10),
            focusedBorder: InputBorder.none,
            border: InputBorder.none,
            enabledBorder: InputBorder.none),
        style: TextStyle(color: ColorConstants.themeColor),
        cursorColor: ColorConstants.themeColor,
      ),
    );
  }

  Widget _prefixIcon() {
    return Container(
        width: 52,
        height: 40,
        margin: const EdgeInsets.only(left: 4),
        alignment: Alignment.center,
        child: IconFont(IconNames.audio, size: 40));
  }

  Widget _suffixIcon() {
    return InkWell(
      radius: 0,
      highlightColor: Colors.transparent,
      onTap: () => controller.changeOption(),
      child: Container(
          width: 44,
          height: 40,
          alignment: Alignment.center,
          child: IconFont(IconNames.add, size: 40)),
    );
  }

  Column _buildStar() {
    return Column(children: [
      BlindButton(
        width: double.infinity,
        height: 50,
        text: '设置为星标好友',
        fontSize: 18,
        color: ColorConstants.themeColor,
        textColor: Colors.black.withOpacity(0.50),
      ),
      CommonWidget.rowHeight(height: 15),
      BlindButton(
          onTap: () => controller.inputWidget(),
          width: double.infinity,
          height: 50,
          text: '取消',
          fontSize: 18,
          color: Colors.transparent)
    ]);
  }

  Row _buildRow() {
    return Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
      IconButton(
          onPressed: () => Get.back(),
          icon: const Icon(Icons.arrow_back_ios,
              color: ColorConstants.themeColor, size: 35)),
      IconButton(
          onPressed: () => controller.inputWidget(),
          icon: IconFont(IconNames.morePoint, size: 35))
    ]);
  }
}
